<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改音乐')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-music-edit" th:object="${adminMusic}">
            <input name="musicId" th:field="*{musicId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">音乐名称：</label>
                <div class="col-sm-8">
                    <input name="musicName" th:field="*{musicName}" class="form-control" type="text">
                </div>
            </div>
            
            <div class="form-group">
	            	<label class="col-sm-3 control-label">上传音乐：</label>
		            <div class="col-sm-6">
	                    <input class="form-control" type="file" name="file" id="file" accept=".mp3">
	                    <input type="hidden" name="music" id="music">
	                </div>
	                <div class="col-sm-2">
	                    <button class="btn btn-success fileinput-button" type="button" id="btnimage">上传</button>
	                </div>
	           </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">音乐时长：</label>
                <div class="col-sm-8">
                    <audio controls="controls" width="20px" id="musicT" name="musicT"></audio>
                    <input type="hidden" name="musicTime" id="musicTime">
                </div>
            </div>
            
            <div class="form-group">    
                <label class="col-sm-3 control-label">音乐专辑介绍：</label>
                <div class="col-sm-8">
                    <input name="album" th:field="*{album}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">音乐介绍：</label>
                <div class="col-sm-8">
                    <input name="introduce" th:field="*{introduce}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_able_status')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}">
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "system/music";
        $("#form-music-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-music-edit').serialize());
            }
        }
        
        $('#btnimage').click(function() {
            var val = $("#file").val();
            if (val.length==0) {
                layer.alert("未选择MP3文件");
                return ;
            }
            var formdata = new FormData();
            formdata.append("file", document.getElementById("file").files[0]);
            $.ajax({
                url: ctx + "system/upload/music",
                data: formdata,
                type: "post",
                processData: false,
                contentType: false,
                success: function(result) {
                	var n=result.fileName;
                	$('#music').val(n);
                	$('#musicTime').val(result.duration);
                	$('#musicT').attr('src',n);
		            var fry_audio=$('#musicT').get('0');
		            fry_audio.load();
                }
            });
        });
    </script>
</body>
</html>